package com.ns.scs.task.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ns.core.annotations.ReqLog;
import com.ns.core.bo.IdsBO;
import com.ns.core.utils.sg.ResultOk;
import com.ns.scs.task.bo.ScheduledLogsPageBO;
import com.ns.scs.task.dto.ScheduledLogsPageDto;
import com.ns.scs.task.service.IScheduledTaskLogsService;
import com.ns.scs.task.vo.ScheduledTaskLogsVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 定时任务-日志接口
 *
 * @author liao.wei
 * @since 2024-05-16
 */
@RestController
@RequestMapping("/scheduled/logs")
@RequiredArgsConstructor
@CrossOrigin
public class ScheduledLogsController {

    private final IScheduledTaskLogsService scheduledTaskLogsService;

    /**
     * 分页查询
     *
     * @param bo 参数
     * @return Result
     */
    @PostMapping("getList")
    @ReqLog(module = "任务日志模块", name = "查-集合")
    public ResultOk selectPage(@RequestBody @Validated ScheduledLogsPageBO bo) {
        ScheduledLogsPageDto dto = new ScheduledLogsPageDto();
        BeanUtils.copyProperties(bo, dto);
        Page<ScheduledTaskLogsVO> page = this.scheduledTaskLogsService.getList(dto);
        return ResultOk.getPageData(page.getTotal(), page.getRecords());
    }

    /**
     * 批量删除
     *
     * @param dto 参数
     * @return ResultOk
     */
    @PostMapping("deleteByIds")
    @ReqLog(module = "任务日志模块", name = "批量删")
    public ResultOk delete(@RequestBody IdsBO dto) {
        return ResultOk.getByBoolean(scheduledTaskLogsService.removeBatchByIds(dto.getIds()));
    }

    /**
     * 查询详情
     *
     * @param id 参数
     * @return Result
     */
    @GetMapping("getById")
    @ReqLog(module = "任务日志模块", name = "查")
    public ResultOk getById(Long id) {
        return ResultOk.getSuccessData(scheduledTaskLogsService.getById(id));
    }

}